<!--
 * @Description: 车辆维护
 * @Author: wangwangwang
 * @Date: 2020-09-21 14:09:06
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-12-29 14:58:19
-->
<template>
  <div class="pages_content table">
    <el-container>
      <el-header>
        <breaDcrumb />
      </el-header>
      <el-main>
        <div class="header_right" @click="showCardNav = !showCardNav">
          <div class="title">搜索</div>
          <div>
            <div :class="{ 'arrowTransform': !showCardNav, 'arrowTransformReturn': showCardNav}">
              <i style="margin-right: 5px" class="el-icon-arrow-down"></i>
            </div>
          </div>
        </div>
        <div v-show="showCardNav" class="hr"></div>
        <el-collapse-transition>
          <div v-show="showCardNav">
            <div class="search">
              <span style="display: inline-block;margin-bottom: 10px;">
                <span style="margin-right: 12px;">车牌号</span>
                <el-input v-model="tableParam.carNo" style="width: 240px;" clearable placeholder="请输入" @keyup.enter.native="gettableData()" />
              </span>
              <span style="margin-left: 24px;">
                <span style="margin-right: 12px;">车辆类型</span>
                <el-select v-model="tableParam.carTypeId" style="width: 240px;" placeholder="请选择">
                  <el-option v-for="item in carTypelist" :key="item.id" :label="item.itemName" :value="item.id"></el-option>
                </el-select>
              </span>
              <el-button icon="el-icon-search" size="medium" class="bottom_all but1" @click="(tableParam.page = 1), gettableData()">查 询</el-button>
              <el-button size="medium" class="bottom_all_two" @click="init()">重 置</el-button>
            </div>
          </div>
        </el-collapse-transition>
        <div class="hr"></div>
        <div class="card">
          <div class="card_nav">
            <div>
              <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='TIANJIA'))!==-1" size="small" class="bottom_all" style="margin-left: 0;" @click="addFromDate('添加')">
                <i class="icon iconfont iconicon_button_add" style="font-size: 12px;"></i>
                添加
              </el-button>
              <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='RIYONG'))!==-1" size="small" class="bottom_three" @click="Update(1)">
                <i class="icon iconfont iconicon_button_startuse" style="font-size: 12px;"></i>
                启用
              </el-button>
              <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='JINYONG'))!==-1" size="small" class="bottom_four" @click="Update(0)">
                <i class="icon iconfont iconicon_button_disable1" style="font-size: 12px;"></i>
                禁用
              </el-button>
            </div>
          </div>
          <div v-loading="tableLoading" class="card_info">
            <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="tableData" tooltip-effect="dark" @selection-change="handleSelectionChange">
              <el-table-column align="center" type="selection"></el-table-column>
              <template v-for="(item, index2) in table">
                <el-table-column v-if="item.status" :key="index2" :label="item.label" align="center" :min-width="item.width" :fixed=" (item.label =='操作'||item.label =='二维码')?'right':false">
                  <template slot-scope="scope">
                    <span v-if="scope.row.enable == 0 && item.label == '状态'" style="color:#969799;">禁用</span>
                    <span v-if="scope.row.enable == 1 && item.label == '状态'" style="color:#00A754;">启用</span>
                    <span v-if="item.label == '使用状况'">空置</span>
                    <el-button v-if="item.label == '操作'&&ButtonList.findIndex(res=>(res.buttonValue=='XIUGAI'))!==-1" class="bottom_one" size="mini" @click="updateFromDate(scope.row, '修改')">
                      <i class="icon iconfont iconicon_button_modification" style="font-size: 12px;"></i>
                      修改
                    </el-button>
                    <div v-if="item.label == '二维码'&&scope.row.codeUrl&&ButtonList.findIndex(res=>(res.buttonValue=='EWEIM'))!==-1" class="table_link">
                      <a :href="'/file/' +scope.row.codeUrl" download>下载二维码</a>
                    </div>
                    <span v-if="item.label !== '操作' && item.label !== '状态' && item.label !== '使用状况' && item.label !== '二维码'">{{ scope.row[item.prop] }}</span>
                  </template>
                </el-table-column>
              </template>
            </el-table>
          </div>
        </div>
      </el-main>
      <div class="card_bottom">
        <div class="card_bottom_left">
          <div class="top_page_totle">总共{{ total }}条</div>
          <el-pagination :current-page.sync="tableParam.page" :page-size="tableParam.pageSize" :page-sizes="[10, 20, 30, 40,50,100,200,500,1000]" layout="prev,pager,sizes,next,jumper" :total="total" @size-change="sizeChange" @current-change="gettableData()"></el-pagination>
        </div>
        <div>
          <el-button size="mini" icon="el-icon-refresh-right" class="bottom_all_two" @click="gettableData">刷新</el-button>
        </div>
      </div>
    </el-container>
    <el-dialog v-dialogDrag :visible.sync="addDialog" width="580px" :close-on-click-modal="false" :before-close="resetFromDate">
      <span slot="title" class="dialog-title">{{ addDialogTitle }}</span>
      <div class="dialoginfo">
        <el-form ref="reffromDate" style="padding: 20px;" :rules="rules" :inline="true" :model="fromDate" label-width="110px">
          <el-form-item prop="companyId">
            <span slot="label" style="color:  #FF0000 ;">所属单位</span>
            <el-select ref="companyId" v-model="fromDate.companyId" placeholder="请选择" @change="$nextTick(()=>{fromDate.company = $refs.companyId.selectedLabel})">
              <el-option v-for="item in companyIdList" :key="item.id" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="carNo">
            <span slot="label" style="color:  #FF0000 ;">车牌号</span>
            <el-input v-model="fromDate.carNo" placeholder="请输入" clearable></el-input>
          </el-form-item>
          <el-form-item prop="carTypeId">
            <span slot="label" style="color:  #FF0000 ;">车辆类型</span>
            <el-select ref="carTypeId" v-model="fromDate.carTypeId" placeholder="请选择" @change="$nextTick(()=>{fromDate.carType = $refs.carTypeId.selectedLabel})">
              <el-option v-for="item in carTypelist" :key="item.id" :label="item.itemName" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="maxCapacity">
            <span slot="label">最大承重</span>
            <el-input v-model="fromDate.maxCapacity" placeholder="请输入" oninput="if(value.length > 11 ){ value = value.slice(0,11)}" onkeypress='return( /\d|\./.test(String.fromCharCode(event.keyCode)))' @input="fromDate.maxCapacity=$regExp.checkNum(fromDate.maxCapacity)" @blur="fromDate.maxCapacity=$regExp.blurCheckNum(fromDate.maxCapacity)">
              <template slot="append">吨</template>
            </el-input>
          </el-form-item>
          <!-- <el-form-item prop="roughWeight">
            <span slot="label">毛重</span>
            <el-input v-model="fromDate.roughWeight" type="Number" placeholder="请输入" clearable>
              <template slot="append">吨</template>
            </el-input>
          </el-form-item> -->
          <el-form-item prop="tare">
            <span slot="label">皮重</span>
            <el-input v-model="fromDate.tare" placeholder="请输入" oninput="if(value.length > 11 ){ value = value.slice(0,11)}" onkeypress='return( /\d|\./.test(String.fromCharCode(event.keyCode)))' @input="fromDate.tare=$regExp.checkNum3(fromDate.tare)" @blur="fromDate.tare=$regExp.blurCheckNum(fromDate.tare)">
              <template slot="append">吨</template>
            </el-input>
          </el-form-item>
          <el-form-item label="状态" prop="enable">
            <el-radio-group v-model="fromDate.enable">
              <el-radio :label="1">启用</el-radio>
              <el-radio :label="0">禁用</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="resetFromDate">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px;" @click="pagessubmitFromDate()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import mixin from "@/mixins/ICPSmixin.js";
import {
  queryPage,
  batchUpdateOrDelete,
  saveOrUpdate,
} from "@/api/smart/specialmaterial/car.js";
import { permissionsCompanyList, getDicType } from "@/api/common.js";
import { carReg } from "@/common/RegExp.js";
export default {
  mixins: [mixin],
  data() {
    var validatePass1 = (rule, value, callback) => {
      if (carReg(value)) {
        callback();
      } else {
        callback(new Error("请输正确的车牌号!"));
      }
    };
    return {
      /*表格增删改查及下载接口*/
      queryPage: queryPage,
      batchUpdateOrDelete: batchUpdateOrDelete,
      saveOrUpdate: saveOrUpdate,
      /*表格数据*/
      table: [
        {
          label: "车辆自编码",
          width: "120",
          prop: "code",
          status: true,
        },
        {
          label: "车牌号",
          width: "100",
          prop: "carNo",
          status: true,
        },
        {
          label: "车牌类型",
          width: "120",
          prop: "carType",
          status: true,
        },
        {
          label: "所属单位",
          width: "160",
          prop: "company",
          status: true,
        },
        {
          label: "最大载重",
          width: "100",
          prop: "maxCapacity",
          status: true,
        },
        // {
        //   label: "毛重(吨)",
        //   width: "100",
        //   prop: "roughWeight",
        //   status: true,
        // },
        {
          label: "皮重(吨)",
          width: "100",
          prop: "tare",
          status: true,
        },
        {
          label: "二维码",
          width: "140",
          prop: "",
          status: true,
        },
        {
          label: "状态",
          width: "100",
          prop: "",
          status: true,
        },
        {
          label: "更新时间",
          width: "160",
          prop: "updateTime",
          status: true,
        },
        {
          label: "操作",
          width: "100",
          prop: "",
          status: true,
        },
      ],
      /*添加表单数据*/
      rules: {
        carNo: [
          { required: true, message: "请输入车牌号", trigger: "change" },
          { validator: validatePass1, trigger: "change", }

        ],
        carTypeId: [
          { required: true, message: "请选择车辆类型", trigger: "change" },
        ],
        companyId: [
          { required: true, message: "请选择所属单位", trigger: "change" },
        ],
        maxCapacity: [
          { required: true, message: "请输入最大承载", trigger: "change" },
        ],
        tare: [{ required: true, message: "请输入皮重", trigger: "change" }],
        roughWeight: [
          { required: true, message: "请输入毛重", trigger: "change" },
        ],
      },
      fromDate: {
        roughWeight: "",
        code: "",
        carNo: "",
        carTypeId: "",
        carTypeName: "",
        company: "",
        companyId: "",
        enable: 1,
        maxCapacity: "",
        tare: "",
      },
      companyIdList: [],
      carTypelist: [],
    };
  },
  async created() {
    this.companyIdList = await permissionsCompanyList()
    this.tableParam = { ...this.tableParam, code: "", carTypeId: "" };
    this.gettableData();
    getDicType({ code: "vanType" }).then((res) => {
      this.carTypelist = res.data.items;
    });
  },
  /*
   *copy(data)深拷贝数据,返回拷贝完的数据
   *gettableData获取列表数据
   *load下载
   *SortNum保持序列号
   * UpdateOrDelete禁用，启用，删除
   * submitFromDate保存更新数据
   */
  methods: {
    pagessubmitFromDate() {
      let _this = this;
      _this.$refs.reffromDate.validate((valid) => {
        if (valid) {
          _this.submitFromDate();
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    init() {
      /*重置数据*/
      this.tableParam.carTypeId = "";
      this.tableParam.carNo = "";
      this.gettableData();
    },
    sizeChange(value) {
      this.tableParam.pageSize = value;
      this.gettableData();
    },
  },
};
</script>

<style lang="scss" scoped>
.dialoginfo {
  .el-input,
  .el-select {
    width: 280px;
  }
}
.table_link {
  margin: 0 0 0 10px;
  border: $bg_color 1px solid;
  color: $bg_color;
  border-radius: 3px;
  font-size: 14px;
  height: 30px;
  background: #ffffff;
  a {
    display: inline-block;
    line-height: 29.31px;
    color: $bg_color;
    text-decoration: none;
    font-size: 14px;
  }
}
</style>
